<template>
  <div>
    <div ref="skyChart" style="width: 100%;height: 230px" />
  </div>
</template>

<script>
import * as echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from '@/components/Mixins/resize'
export default {
  name: 'SkyDataChart',
  mixins: [resize],
  props: {
    skyData: {
      type: Array,
      default: []
    }
  },
  data() {
    return {
      chart: null
    }
  },
  watch: {
    skyData: {
      deep: true,
      handler() {
        this.showChart()
      }
    }
  },
  mounted() {
    const that = this
    this.$nextTick(() => {
      that.showChart()
    })
  },
  methods: {
    showChart() {
      const that = this
      this.chart = echarts.init(this.$refs.skyChart, 'macarons')
      this.chart.setOption({
        radar: {
          indicator: [
            { name: that.$t('pm10'), max: 500 },
            { name: that.$t('pm25'), max: 500 },
            { name: that.$t('sunLight'), max: 200000 },
            { name: that.$t('airHumidity'), max: 100 },
            { name: that.$t('airTemperature'), max: 250 },
            { name: that.$t('airPressure'), max: 1100 },
            { name: that.$t('co2'), max: 5000 }
          ],
          shape: 'circle',
          splitNumber: 5,
          name: {
            textStyle: {
              color: '#FFF'
            }
          },
          // splitLine: {
          //   lineStyle: {
          //     color: [
          //       'rgba(238, 197, 102, 0.1)', 'rgba(238, 197, 102, 0.2)',
          //       'rgba(238, 197, 102, 0.4)', 'rgba(238, 197, 102, 0.6)',
          //       'rgba(238, 197, 102, 0.8)', 'rgba(238, 197, 102, 1)'
          //     ].reverse()
          //   }
          // },
          // splitArea: {
          //   show: false
          // },
          axisLine: {
            lineStyle: {
              color: '#FFF'
            }
          }
        },
        series: [
          {
            name: '北京',
            type: 'radar',
            lineStyle: {
              normal: {
                width: 1,
                opacity: 0.5
              }
            },
            data: [
              that.skyData
            ],
            symbol: 'none',
            itemStyle: {
              color: '#F9713C'
            },
            areaStyle: {
              opacity: 0.1
            }
          }]
      })
    }
  }
}
</script>


